﻿using System;using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.SqlServer.Dts.Pipeline;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

namespace ToddMcDermid.SSIS
{
    /// <summary>
    /// 
    /// </summary>
    [DtsPipelineComponent(
        DisplayName = "Replacing Data Conversion",
        CurrentVersion = 0,
        ComponentType = ComponentType.Transform,
        IconResource = "ToddMcDermid.SSIS.Replacing Data Conversion.ico",
        UITypeName = "ToddMcDermid.SSIS.ReplacingDataConversionUI, ReplacingDataConversion100, Version=1.0.0.0, Culture=neutral, PublicKeyToken=816a54fea1f2ce30"
        )]
    public class ReplacingDataConversion : PipelineComponent
    {
        #region Private Variables
        // Runtime
        private ReplacingDataConversionConfiguration _runtimeConfiguration;
        private PipelineBuffer _outputStandardBuffer;
        private PipelineBuffer _errorOutputBuffer;
        #endregion

        #region Constructor
        /// <summary>
        /// </summary>
        public ReplacingDataConversion()
        { }
        #endregion

        #region ProvideComponentProperties
        /// <summary>
        /// Initializes the component with default settings
        /// </summary>
        /// <remarks>Called by SSIS when the component is first added to a dataflow task</remarks>
        public override void ProvideComponentProperties()
        {
            this.RemoveAllInputsOutputsAndCustomProperties();
            this.ComponentMetaData.UsesDispositions = true;

            #region Set metadata version
            DtsPipelineComponentAttribute componentAttribute =
              (DtsPipelineComponentAttribute)Attribute.GetCustomAttribute(this.GetType(), typeof(DtsPipelineComponentAttribute), false);
            int runtimeVersion = componentAttribute.CurrentVersion;
            ComponentMetaData.Version = runtimeVersion;
            #endregion

            ReplacingDataConversionConfiguration configuration = new ReplacingDataConversionConfiguration(ComponentMetaData);
            configuration.ReinitializeMetaData();
        }
        #endregion

        #region PerformUpgrade
        public override void PerformUpgrade(int pipelineVersion)
        {
            // Obtain the current component version from the attribute.
            DtsPipelineComponentAttribute componentAttribute =
              (DtsPipelineComponentAttribute)Attribute.GetCustomAttribute(this.GetType(), typeof(DtsPipelineComponentAttribute), false);
            int runtimeVersion = componentAttribute.CurrentVersion;
            int metadataVersion = ComponentMetaData.Version;

            if (runtimeVersion != metadataVersion)
            {
                // Configuration object is not loaded
                // Make adjustments directly to ComponentMetaData ONLY
                #region Upgrade to v1
                if (metadataVersion <= 0)
                {
                }
                #endregion

                // Update the saved component version metadata to the current version.
                ComponentMetaData.Version = runtimeVersion;
            }
        }
        #endregion

        #region Validate
        /// <summary>
        /// Verifies that the component is correctly configured
        /// </summary>
        /// <remarks>Called repeatedly by SSIS during design time for validation and once before execution</remarks>
        /// <returns>The status of the validation</returns>
        public override DTSValidationStatus Validate()
        {
            DTSValidationStatus status = base.Validate();

            if (status == DTSValidationStatus.VS_ISVALID)
            {
                ReplacingDataConversionConfiguration configuration;
                if (this._runtimeConfiguration != null)
                {
                    configuration = this._runtimeConfiguration;
                }
                else
                {
                    configuration = new ReplacingDataConversionConfiguration(ComponentMetaData);
                }
                status = configuration.Validate();
            }

            return status;
        }

        #endregion

        #region ReinitializeMetaData
        /// <summary>
        /// </summary>
        public override void ReinitializeMetaData()
        {
            ReplacingDataConversionConfiguration configuration = new ReplacingDataConversionConfiguration(ComponentMetaData);
            configuration.ReinitializeMetaData();
        }
        #endregion

        #region OnInputPathAttached
        /// <summary>
        /// Called when the component is attached to an upstream component. Automatically map all of the columns
        /// from the virtual input by calling SetUsageType.
        /// </summary>
        /// <param name="inputID">The ID of the input that is attached.</param>
        public override void OnInputPathAttached(int inputID)
        {
            this.ReinitializeMetaData();
        }
        #endregion

        #region PreExecute
        /// <summary>
        /// Set up the dataset 
        /// For each IDTSInput100, create a DataTable in the DataSet
        /// For each IDTSInputColumn100, create a DataColumn in the DataTable.
        /// During ProcessInput these DataTables and DataColumns are populated from the Buffer provided by 
        /// the DataFlow engine.
        /// </summary>
        public override void PreExecute()
        {
            bool pbCancel;

            this._runtimeConfiguration = new ReplacingDataConversionConfiguration(ComponentMetaData);
            foreach (ColumnConversionConfig columnConfig in this._runtimeConfiguration.CustomProperties.ColumnConversionConfigs)
            {
                try
                {
                    if (columnConfig.WantToOutput)
                    {
                        columnConfig.RuntimeInBufferIndex = BufferManager.FindColumnByLineageID(this._runtimeConfiguration.Inputs.Input.Buffer, columnConfig.InLineageID);
                    }
                }
                #region catch ...
                catch (Exception ex)
                {
                    ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to find input column with lineage ID of " 
                        + columnConfig.InLineageID.ToString() + ": " + ex.Message, "", 0, out pbCancel);
                }
                #endregion
            }
        }
        #endregion

        #region PrimeOutput
        public override void PrimeOutput(int outputs, int[] outputIDs, PipelineBuffer[] buffers)
        {
            bool pbCancel;

            #region Cache buffers
            for (int outputIndex = 0; outputIndex < outputs; outputIndex++)
            {
                if (outputIDs[outputIndex] == this._runtimeConfiguration.Outputs.Standard.ID)
                {
                    this._outputStandardBuffer = buffers[outputIndex];
                }
                else if (outputIDs[outputIndex] == this._runtimeConfiguration.Outputs.Error.ID)
                {
                    this._errorOutputBuffer = buffers[outputIndex];
                }
            }
            #endregion

            #region Cache column locations in the buffers
            foreach (ColumnConversionConfig columnConfig in this._runtimeConfiguration.CustomProperties.ColumnConversionConfigs)
            {
                try
                {
                    if (columnConfig.WantToOutput)
                    {
                        columnConfig.RuntimeOutBufferIndex = BufferManager.FindColumnByLineageID(this._runtimeConfiguration.Outputs.Standard.Buffer, columnConfig.OutLineageID);
                    }
                }
                #region catch ...
                catch (Exception ex)
                {
                    ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to find output column with lineage ID of "
                        + columnConfig.OutLineageID.ToString() + ": " + ex.Message, "", 0, out pbCancel);
                }
                #endregion
                if ((this._runtimeConfiguration.Outputs.Error.IsAttached) && (columnConfig.WantToOutput))
                {
                    try
                    {
                        columnConfig.RuntimeErrorBufferIndex = BufferManager.FindColumnByLineageID(this._runtimeConfiguration.Outputs.Error.Buffer, columnConfig.ErrorLineageID);
                    }
                    #region catch ...
                    catch (Exception ex)
                    {
                        ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to find error output column with lineage ID of "
                            + columnConfig.ErrorLineageID.ToString() + ": " + ex.Message, "", 0, out pbCancel);
                    }
                    #endregion
                }
            }
            #endregion
        }
        #endregion

        #region ProcessInput
        /// <summary>
        /// Add the rows from the input buffer to the to the DataSet.
        /// </summary>
        /// <param name="inputID">The ID of the IDTSInput100</param>
        /// <param name="buffer">The PipelineBuffer containing the records to process</param>
        public override void ProcessInput(int inputID, PipelineBuffer buffer)
        {
            bool pbCancel;

            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            while (buffer.NextRow() == true)
            {
                this._outputStandardBuffer.AddRow();
                foreach (ColumnConversionConfig columnConfig in this._runtimeConfiguration.CustomProperties.ColumnConversionConfigs)
                {
                    try
                    {
                        if (!buffer.IsNull(columnConfig.RuntimeInBufferIndex))
                        {
                            #region Convert data
                            switch (columnConfig.InDataType)
                            {
                                case DataType.DT_BOOL:
                                    #region Boolean
                                    bool boolValue = buffer.GetBoolean(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, boolValue);
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            if (boolValue)
                                            {
                                                this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, 0M);
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, 1M);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            if (boolValue)
                                            {
                                                this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, 0);
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, 1);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            if (boolValue)
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, 0);
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, 1);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            #region Int32
                                            if (boolValue)
                                            {
                                                this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, 0);
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, 1);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I8:
                                            #region Int64
                                            if (boolValue)
                                            {
                                                this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, 0);
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, 1);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            if (boolValue)
                                            {
                                                this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, 0);
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, 1);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            if (boolValue)
                                            {
                                                this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, 0);
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, 1);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            string convertedBool = "False";
                                            if (boolValue)
                                            {
                                                convertedBool = "True";
                                            }
                                            try
                                            {
                                                this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, convertedBool);
                                            }
                                            catch (DoesNotFitBufferException)
                                            {
                                                if (columnConfig.TruncationRowDisposition == DTSRowDisposition.RD_IgnoreFailure)
                                                {
                                                    this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, convertedBool.Substring(0, columnConfig.OutLength));
                                                }
                                                else
                                                {
                                                    throw;
                                                }
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt16
                                            if (boolValue)
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, 0);
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, 1);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            if (boolValue)
                                            {
                                                this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, 0);
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, 1);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            if (boolValue)
                                            {
                                                this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, 0);
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, 1);
                                            }
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_CY:
                                case DataType.DT_DECIMAL:
                                case DataType.DT_FILETIME:
                                case DataType.DT_NUMERIC:
                                    #region Numeric/Decimal
                                    decimal decValue = buffer.GetDecimal(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, (decValue != 0M));
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, decValue);
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            if ((decValue >= byte.MinValue) && (decValue <= byte.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, Convert.ToByte(decValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() 
                                                    + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            if ((decValue >= Int16.MinValue) && (decValue <= Int16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToInt16(decValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() 
                                                    + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            #region Int32
                                            if ((decValue >= Int32.MinValue) && (decValue <= Int32.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToInt32(decValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() 
                                                    + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I8:
                                            #region Int64
                                            if ((decValue >= Int64.MinValue) && (decValue <= Int64.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToInt64(decValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            try
                                            {
                                                this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, Convert.ToSingle(decValue));
                                            }
                                            catch
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() 
                                                    + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            try
                                            {
                                                this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, Convert.ToDouble(decValue));
                                            }
                                            catch
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() 
                                                    + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            try
                                            {
                                                this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, decValue.ToString());
                                            }
                                            catch
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() 
                                                    + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt16
                                            if ((decValue >= UInt16.MinValue) && (decValue <= UInt16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt16(decValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            if ((decValue >= UInt32.MinValue) && (decValue <= UInt32.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt32(decValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            if ((decValue >= UInt64.MinValue) && (decValue <= UInt64.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt64(decValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_DBDATE:
                                    #region Date
                                    DateTime dateValue = buffer.GetDate(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            // illegal
                                            break;

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            // illegal
                                            break;

                                        case DataType.DT_DBDATE:
                                            #region Date
                                            this._outputStandardBuffer.SetDate(columnConfig.RuntimeOutBufferIndex, dateValue);
                                            break;
                                            #endregion

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            #region DateTime
                                            this._outputStandardBuffer.SetDateTime(columnConfig.RuntimeOutBufferIndex, dateValue);
                                            break;
                                            #endregion

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            // illegal
                                            break;

                                        case DataType.DT_I2:
                                            // illegal
                                            break;

                                        case DataType.DT_I4:
                                            // illegal
                                            break;

                                        case DataType.DT_I8:
                                            // illegal
                                            break;

                                        case DataType.DT_R4:
                                            // illegal
                                            break;

                                        case DataType.DT_R8:
                                            // illegal
                                            break;

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            if (columnConfig.OutLength < ColumnConversionConfig.STRINGFORMAT_DATE.Length)
                                            {
                                                throw new Exception("Truncation error converting date to string.");
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, dateValue.ToString(ColumnConversionConfig.STRINGFORMAT_DATE));
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            // illegal
                                            break;

                                        case DataType.DT_UI4:
                                            // illegal
                                            break;

                                        case DataType.DT_UI8:
                                            // illegal
                                            break;
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_DATE:
                                case DataType.DT_DBTIMESTAMP:
                                    #region DateTime
                                    DateTime dateTimeValue = buffer.GetDateTime(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            // illegal
                                            break;

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            // illegal
                                            break;

                                        case DataType.DT_DBDATE:
                                            #region Date
                                            this._outputStandardBuffer.SetDate(columnConfig.RuntimeOutBufferIndex, dateTimeValue.Date);
                                            break;
                                            #endregion

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            #region DateTime
                                            this._outputStandardBuffer.SetDateTime(columnConfig.RuntimeOutBufferIndex, dateTimeValue);
                                            break;
                                            #endregion

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            // illegal
                                            break;

                                        case DataType.DT_I2:
                                            // illegal
                                            break;

                                        case DataType.DT_I4:
                                            // illegal
                                            break;

                                        case DataType.DT_I8:
                                            // illegal
                                            break;

                                        case DataType.DT_R4:
                                            // illegal
                                            break;

                                        case DataType.DT_R8:
                                            // illegal
                                            break;

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            if (columnConfig.OutLength < ColumnConversionConfig.STRINGFORMAT_DATETIME.Length)
                                            {
                                                throw new Exception("Truncation error converting DateTime to String.");
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, dateTimeValue.ToString(ColumnConversionConfig.STRINGFORMAT_DATETIME));
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            // illegal
                                            break;

                                        case DataType.DT_UI4:
                                            // illegal
                                            break;

                                        case DataType.DT_UI8:
                                            // illegal
                                            break;
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_GUID:
                                    #region GUID
                                    Guid guidValue = buffer.GetGuid(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            // illegal
                                            break;

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            // illegal
                                            break;

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            #region GUID
                                            this._outputStandardBuffer.SetGuid(columnConfig.RuntimeOutBufferIndex, guidValue);
                                            break;
                                            #endregion

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            // illegal
                                            break;

                                        case DataType.DT_I2:
                                            // illegal
                                            break;

                                        case DataType.DT_I4:
                                            // illegal
                                            break;

                                        case DataType.DT_I8:
                                            // illegal
                                            break;

                                        case DataType.DT_R4:
                                            // illegal
                                            break;

                                        case DataType.DT_R8:
                                            // illegal
                                            break;

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            if (columnConfig.OutLength < 36)
                                            {
                                                throw new Exception("Truncation error converting GUID to String.");
                                            }
                                            else
                                            {
                                                this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, guidValue.ToString());
                                                break;
                                            }
                                            #endregion

                                        case DataType.DT_UI2:
                                            // illegal
                                            break;

                                        case DataType.DT_UI4:
                                            // illegal
                                            break;

                                        case DataType.DT_UI8:
                                            // illegal
                                            break;
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_I1:
                                case DataType.DT_UI1:
                                    #region Byte
                                    byte byteValue = buffer.GetByte(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, (byteValue != 0));
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, Convert.ToDecimal(byteValue));
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, byteValue);
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToInt16(byteValue));
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            #region Int32
                                            this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToInt32(byteValue));
                                            break;
                                            #endregion

                                        case DataType.DT_I8:
                                            #region Int64
                                            this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToInt64(byteValue));
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, Convert.ToSingle(byteValue));
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, Convert.ToDouble(byteValue));
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, byteValue.ToString());
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt16
                                            this._outputStandardBuffer.SetUInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt16(byteValue));
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            this._outputStandardBuffer.SetUInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt32(byteValue));
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            this._outputStandardBuffer.SetUInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt64(byteValue));
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_I2:
                                    #region Int16
                                    Int16 int16Value = buffer.GetInt16(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, (int16Value != 0));
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, Convert.ToDecimal(int16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            if ((int16Value >= byte.MinValue) && (int16Value <= byte.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, Convert.ToByte(int16Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, int16Value);
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            #region Int32
                                            this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToInt32(int16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_I8:
                                            #region Int64
                                            this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToInt64(int16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, Convert.ToSingle(int16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, Convert.ToDouble(int16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, int16Value.ToString());
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt16
                                            if (int16Value >= UInt16.MinValue)
                                            {
                                                this._outputStandardBuffer.SetUInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt16(int16Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            this._outputStandardBuffer.SetUInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt32(int16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            this._outputStandardBuffer.SetUInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt64(int16Value));
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_I4:
                                    #region Int32
                                    Int32 int32Value = buffer.GetInt32(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, (int32Value != 0));
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, Convert.ToDecimal(int32Value));
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            if ((int32Value >= byte.MinValue) && (int32Value <= byte.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, Convert.ToByte(int32Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            if ((int32Value >= Int16.MinValue) && (int32Value <= Int16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToInt16(int32Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            #region Int32
                                            this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, int32Value);
                                            break;
                                            #endregion

                                        case DataType.DT_I8:
                                            #region Int64
                                            this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToInt64(int32Value));
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, Convert.ToSingle(int32Value));
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, Convert.ToDouble(int32Value));
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, int32Value.ToString());
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt16
                                            if ((int32Value >= UInt16.MinValue) && (int32Value <= UInt16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt16(int32Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            if (int32Value >= UInt32.MinValue)
                                            {
                                                this._outputStandardBuffer.SetUInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt32(int32Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            this._outputStandardBuffer.SetUInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt64(int32Value));
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_I8:
                                    #region Int64
                                    Int64 int64Value = buffer.GetInt64(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, (int64Value != 0));
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, Convert.ToDecimal(int64Value));
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            if ((int64Value >= byte.MinValue) && (int64Value <= byte.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, Convert.ToByte(int64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            if ((int64Value >= Int16.MinValue) && (int64Value <= Int16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToInt16(int64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            #region Int32
                                            if ((int64Value >= Int32.MinValue) && (int64Value <= Int32.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToInt32(int64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I8:
                                            #region Int64
                                            this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, int64Value);
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, Convert.ToSingle(int64Value));
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, Convert.ToDouble(int64Value));
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, int64Value.ToString());
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt16
                                            if ((int64Value >= UInt16.MinValue) && (int64Value <= UInt16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt16(int64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            if ((int64Value >= UInt32.MinValue) && (int64Value <= UInt32.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt32(int64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            if (int64Value >= 0)
                                            {
                                                this._outputStandardBuffer.SetUInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt64(int64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_R4:
                                    #region Single
                                    Single singleValue = buffer.GetSingle(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, (singleValue != 0));
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, Convert.ToDecimal(singleValue));
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            if ((singleValue >= byte.MinValue) && (singleValue <= byte.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, Convert.ToByte(singleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            if ((singleValue >= Int16.MinValue) && (singleValue <= Int16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToInt16(singleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            #region Int32
                                            if ((singleValue >= Int32.MinValue) && (singleValue <= Int32.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToInt32(singleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I8:
                                            #region Int64
                                            if ((singleValue >= Int64.MinValue) && (singleValue <= Int64.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToInt64(singleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, singleValue);
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, Convert.ToDouble(singleValue));
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, singleValue.ToString());
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt16
                                            if ((singleValue >= UInt16.MinValue) && (singleValue <= UInt16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt16(singleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            if ((singleValue >= UInt32.MinValue) && (singleValue <= UInt32.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt32(singleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            if ((singleValue >= UInt64.MinValue) && (singleValue <= UInt64.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt64(singleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_R8:
                                    #region Double
                                    Double doubleValue = buffer.GetDouble(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, (doubleValue != 0));
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, Convert.ToDecimal(doubleValue));
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            if ((doubleValue >= byte.MinValue) && (doubleValue <= byte.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, Convert.ToByte(doubleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            if ((doubleValue >= Int16.MinValue) && (doubleValue <= Int16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToInt16(doubleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            #region Int32
                                            if ((doubleValue >= Int32.MinValue) && (doubleValue <= Int32.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToInt32(doubleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I8:
                                            #region Int64
                                            if ((doubleValue >= Int64.MinValue) && (doubleValue <= Int64.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToInt64(doubleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, Convert.ToSingle(doubleValue));
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, doubleValue);
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, doubleValue.ToString());
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt16
                                            if ((doubleValue >= UInt16.MinValue) && (doubleValue <= UInt16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt16(doubleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            if ((doubleValue >= UInt32.MinValue) && (doubleValue <= UInt32.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt32(doubleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            if ((doubleValue >= UInt64.MinValue) && (doubleValue <= UInt64.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt64(doubleValue));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_STR:
                                case DataType.DT_WSTR:
                                    #region String
                                    string stringValue = buffer.GetString(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, (stringValue == "True"));
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, Convert.ToDecimal(stringValue));
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            #region Date
                                            try
                                            {
                                                this._outputStandardBuffer.SetDate(columnConfig.RuntimeOutBufferIndex, Convert.ToDateTime(stringValue).Date);
                                            }
                                            catch (Exception ex)
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString()
                                                    + " to " + columnConfig.OutDataType.ToString() + ": " + ex.Message, "", 0, out pbCancel);
                                            }
                                            #endregion
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            #region DateTime
                                            try
                                            {
                                                this._outputStandardBuffer.SetDateTime(columnConfig.RuntimeOutBufferIndex, Convert.ToDateTime(stringValue));
                                            }
                                            catch (Exception ex)
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString()
                                                    + " to " + columnConfig.OutDataType.ToString() + ": " + ex.Message, "", 0, out pbCancel);
                                            }
                                            #endregion
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, Convert.ToByte(stringValue));
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToInt16(stringValue));
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            #region Int32
                                            this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToInt32(stringValue));
                                            break;
                                            #endregion

                                        case DataType.DT_I8:
                                            #region Int64
                                            this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToInt64(stringValue));
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, Convert.ToSingle(stringValue));
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, Convert.ToDouble(stringValue));
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, stringValue);
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt16
                                            this._outputStandardBuffer.SetUInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt16(stringValue));
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            this._outputStandardBuffer.SetUInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt32(stringValue));
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            this._outputStandardBuffer.SetUInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt64(stringValue));
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_UI2:
                                    #region UInt16
                                    UInt16 uint16Value = buffer.GetUInt16(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, (uint16Value != 0));
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, Convert.ToDecimal(uint16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            if ((uint16Value >= byte.MinValue) && (uint16Value <= byte.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, Convert.ToByte(uint16Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            if (uint16Value <= Int16.MaxValue)
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToInt16(uint16Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            #region Int32
                                            this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToInt32(uint16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_I8:
                                            #region Int64
                                            this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToInt64(uint16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, Convert.ToSingle(uint16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, Convert.ToDouble(uint16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, uint16Value.ToString());
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt16
                                            this._outputStandardBuffer.SetUInt16(columnConfig.RuntimeOutBufferIndex, uint16Value);
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            this._outputStandardBuffer.SetUInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt32(uint16Value));
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            this._outputStandardBuffer.SetUInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt64(uint16Value));
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_UI4:
                                    #region UInt32
                                    UInt32 uint32Value = buffer.GetUInt32(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, (uint32Value != 0));
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, Convert.ToDecimal(uint32Value));
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            if ((uint32Value >= byte.MinValue) && (uint32Value <= byte.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, Convert.ToByte(uint32Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            if (uint32Value <= Int16.MaxValue)
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToInt16(uint32Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            // illegal
                                            break;

                                        case DataType.DT_I8:
                                            #region Int64
                                            this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToInt64(uint32Value));
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, Convert.ToSingle(uint32Value));
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, Convert.ToDouble(uint32Value));
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, uint32Value.ToString());
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt16
                                            if ((uint32Value >= UInt16.MinValue) && (uint32Value <= UInt16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt16(uint32Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            this._outputStandardBuffer.SetUInt32(columnConfig.RuntimeOutBufferIndex, uint32Value);
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            this._outputStandardBuffer.SetUInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt64(uint32Value));
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;

                                case DataType.DT_UI8:
                                    #region UInt64
                                    UInt64 uint64Value = buffer.GetUInt64(columnConfig.RuntimeInBufferIndex);
                                    switch (columnConfig.OutDataType)
                                    {
                                        case DataType.DT_BOOL:
                                            #region Boolean
                                            this._outputStandardBuffer.SetBoolean(columnConfig.RuntimeOutBufferIndex, (uint64Value != 0));
                                            break;
                                            #endregion

                                        case DataType.DT_CY:
                                        case DataType.DT_DECIMAL:
                                        case DataType.DT_FILETIME:
                                        case DataType.DT_NUMERIC:
                                            #region Decimal
                                            this._outputStandardBuffer.SetDecimal(columnConfig.RuntimeOutBufferIndex, Convert.ToDecimal(uint64Value));
                                            break;
                                            #endregion

                                        case DataType.DT_DBDATE:
                                            // illegal
                                            break;

                                        case DataType.DT_DATE:
                                        case DataType.DT_DBTIMESTAMP:
                                            // illegal
                                            break;

                                        case DataType.DT_GUID:
                                            // illegal
                                            break;

                                        case DataType.DT_I1:
                                        case DataType.DT_UI1:
                                            #region Byte
                                            if ((uint64Value >= byte.MinValue) && (uint64Value <= byte.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetByte(columnConfig.RuntimeOutBufferIndex, Convert.ToByte(uint64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I2:
                                            #region Int16
                                            if (uint64Value <= (UInt64)Int16.MaxValue)
                                            {
                                                this._outputStandardBuffer.SetInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToInt16(uint64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I4:
                                            #region Int32
                                            if (uint64Value <= Int32.MaxValue)
                                            {
                                                this._outputStandardBuffer.SetInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToInt32(uint64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_I8:
                                            #region Int64
                                            if (uint64Value <= Int64.MaxValue)
                                            {
                                                this._outputStandardBuffer.SetInt64(columnConfig.RuntimeOutBufferIndex, Convert.ToInt64(uint64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_R4:
                                            #region Single
                                            this._outputStandardBuffer.SetSingle(columnConfig.RuntimeOutBufferIndex, Convert.ToSingle(uint64Value));
                                            break;
                                            #endregion

                                        case DataType.DT_R8:
                                            #region Double
                                            this._outputStandardBuffer.SetDouble(columnConfig.RuntimeOutBufferIndex, Convert.ToDouble(uint64Value));
                                            break;
                                            #endregion

                                        case DataType.DT_STR:
                                        case DataType.DT_WSTR:
                                            #region String
                                            this._outputStandardBuffer.SetString(columnConfig.RuntimeOutBufferIndex, uint64Value.ToString());
                                            break;
                                            #endregion

                                        case DataType.DT_UI2:
                                            #region UInt126
                                            if ((uint64Value >= UInt16.MinValue) && (uint64Value <= UInt16.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt16(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt16(uint64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI4:
                                            #region UInt32
                                            if ((uint64Value >= UInt32.MinValue) && (uint64Value <= UInt32.MaxValue))
                                            {
                                                this._outputStandardBuffer.SetUInt32(columnConfig.RuntimeOutBufferIndex, Convert.ToUInt32(uint64Value));
                                            }
                                            else
                                            {
                                                ComponentMetaData.FireError(0, ComponentMetaData.Name, "Unable to convert " + columnConfig.InDataType.ToString() + " to " + columnConfig.OutDataType.ToString() + " - out of range.", "", 0, out pbCancel);
                                            }
                                            break;
                                            #endregion

                                        case DataType.DT_UI8:
                                            #region UInt64
                                            this._outputStandardBuffer.SetUInt64(columnConfig.RuntimeOutBufferIndex, uint64Value);
                                            break;
                                            #endregion
                                    }
                                    #endregion
                                    break;
                            }
                            #endregion
                        }
                    }
                    #region catch... truncation errors
                    catch (DoesNotFitBufferException dnfbex)
                    {
                        switch (columnConfig.TruncationRowDisposition)
                        {
                            case DTSRowDisposition.RD_IgnoreFailure:
                                // leave this column empty
                                break;

                            case DTSRowDisposition.RD_RedirectRow:
                                // send the row to the error output
                                this._errorOutputBuffer.AddRow();

                                foreach (ColumnConversionConfig errorColumnConfig in this._runtimeConfiguration.CustomProperties.ColumnConversionConfigs)
                                {
                                    this._errorOutputBuffer[errorColumnConfig.RuntimeErrorBufferIndex] = buffer[errorColumnConfig.RuntimeInBufferIndex];
                                }
                                this._errorOutputBuffer.SetErrorInfo(this._runtimeConfiguration.Outputs.Error.ID, 1, columnConfig.InLineageID);
                                break;

                            default:
                                // fail the component
                                throw new Exception("The Replacing Data Conversion component '" + ComponentMetaData.Name + "' "
                                    + "failed converting '" + columnConfig.ColumnName + "' because truncation occurred, "
                                    + "and the truncation row disposition specifies failure on truncation.");
                        }
                    }
                    #endregion
                    #region catch ... other conversion errors
                    catch (Exception ex)
                    {
                        switch (columnConfig.ErrorRowDisposition)
                        {
                            case DTSRowDisposition.RD_IgnoreFailure:
                                // leave the column empty
                                break;

                            case DTSRowDisposition.RD_RedirectRow:
                                // send the row to the error output
                                this._errorOutputBuffer.AddRow();

                                foreach (ColumnConversionConfig errorColumnConfig in this._runtimeConfiguration.CustomProperties.ColumnConversionConfigs)
                                {
                                    this._errorOutputBuffer[errorColumnConfig.RuntimeErrorBufferIndex] = buffer[errorColumnConfig.RuntimeInBufferIndex];
                                }
                                this._errorOutputBuffer.SetErrorInfo(this._runtimeConfiguration.Outputs.Error.ID, 1, columnConfig.InLineageID);
                                break;

                            default:
                                // fail the component
                                throw new Exception("The Replacing Data Conversion component '" + ComponentMetaData.Name + "' "
                                    + "failed converting '" + columnConfig.ColumnName + "', "
                                    + "and the error row disposition specifies failure.", ex);
                        }
                    }
                    #endregion
                }
            }

            if (buffer.EndOfRowset)
            {
                this._outputStandardBuffer.SetEndOfRowset();
                if (this._errorOutputBuffer != null)
                {
                    this._errorOutputBuffer.SetEndOfRowset();
                }
            }
        }
        #endregion
    }
}